package cn.lixu._01sync;


import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;

/**
 * @author LiXu
 * @date 2022/08/16 0016 14:58:05
 */
public class Producter {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        //1.获取Producter对象
        DefaultMQProducer producer = new DefaultMQProducer("sync_product_group");
        //2.设置nameserver地址值
        producer.setNamesrvAddr("localhost:9876");
        //3.启动
        producer.start();
        //4.创建消息对象，设置消息
        // topic：消息主题 tags：此主题下的二级分类 body：消息的字节
        Message message = new Message("hello_topic", "hello", "我爱中国".getBytes(StandardCharsets.UTF_8));
        // 4.2.发送消息
        SendResult send = producer.send(message);
        // 4.3.打印消息发送结果
        System.out.println(send);
        //5.关闭
        producer.shutdown();

    }
}
